<!DOCTYPE html>
<html lang="en">
	<head>
		<title>网银缴费</title>
		<#include "../inc/header.ftl"/>
	</head>

	<body class="no-skin">

		<div class="main-container ace-save-state" id="main-container">

			<div class="main-content">
				<div class="main-content-inner">

					<div class="page-content">
						<div class="row">
							<div class="col-xs-12">
								<table id="MainGrid"></table>
								<div id="toolbar">
									<div style="padding:8px">
                                        银行账号：<input id="accountnum" name="accountnum">
                                        日期：<input id="accountdate1" class="easyui-datebox" style="width:140px">&emsp;
                                        <a href="#" onclick="javascript:searchInfo()" class="easyui-linkbutton" iconCls="icon-search">查 询</a>
                                    </div><br>
                                    <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="javascript:editInfo(1)">新增</a>
                                    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="javascript:editInfo(2)">修改</a>
                                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" id="delet" onclick="javascript:deleteInfo()">删除</a>
                                    <a href="#" class="easyui-linkbutton" iconCls="icon-print" onclick="javascript:exportInfo()">导出</a>

                                </div>
							</div>
						</div><!-- /.row -->
					</div><!-- /.page-content -->
                    <div id="box-update" class="ui-dialog-content hide" data-options="minimizable:true,maximizable:true">
                        <form class="form-horizontal" id="form-update" method="post">
                            <div class="form-group">
                                <input type="text" name="bankcheckid" id="bankcheckid" hidden/>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">银行名称&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="bankid" id="bankid" data-options="required:true" style="width: 100%;"/>
                                    </span>
                                </div>
                                <input type="text" name="waitaffirmpayid" id="waitaffirmpayid" hidden/>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">账户&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="accountcode" id="accountcode" style="width: 170px"
                                               readonly="true">
                                    </span>
                                </div>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">账户名称</label>
                                <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="accountname" id="accountname" style="width: 170px" readonly="true">
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">日期</label>
                                <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="accountdate" id="accountdate"
                                               class="easyui-datetimebox col-xs-12 easyui-validatebox" style="width: 100%"/>
                                    </span>
                                </div>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">金额&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                          <input type="text" name="money" id="money"
                                                 class="col-xs-12 easyui-validatebox" data-options="required:true"/>
                                    </span>
                                </div>

                            </div>
                        </form>
                    </div><!-- #dialog-confirm -->

                    <div id="SendBox-add" class="ui-dialog-content hide">
                        <div style="padding:8px">
                            复核用户编码：<input id="usercode" class="easyui-textbox" style="width:140px" data-options="required:true" >&emsp;
                            复核用户密码：<input id="userpwd" class="easyui-textbox" style="width:140px" data-options="required:true" >&emsp;
                            <input id="biaoshi" hidden>&emsp;
                            <a href="#" class="easyui-linkbutton" iconCls="icon-redo"  onclick="javascript:pageSendInfo()"><span  id="sendClean"></span></a>
                            <a href="#" class="easyui-linkbutton" iconCls="icon-back" onclick="javascript:cancelInfo()"><span id="sendCleanCan"></span></a>
                        </div>
                        <table id="SendMainGrid"></table>
                    </div>
                </div>
			</div><!-- /.main-content -->
		</div><!-- /.main-container -->

		<!-- basic scripts -->
		<#include "../inc/basicjs.ftl"/>

		<!-- inline scripts related to this page -->
		<script type="text/javascript">
            //列表-------------------------------------------------
			jQuery(function($) {
                listPage();
			});

			function searchInfo() {
				listPage(prefix + '/bill/bankcheckbill/selwebpay',1)
			}

            function listPage(url,mark){
			    if(mark==1){
                    var accountnum = $('#accountnum').val();
                    var accountdate = $('#accountdate1').val();
                    // if(accountnum==null||accountnum==''){
                    //     $.messager.alert('提示', '请选择收款账户', 'info');
                    //     return;
                    // }
                }
                // 右侧表格
                $('#MainGrid').datagrid({
                    url:url,
                    checkbox: true,
                    pagination: true,
                    fitColumns:true,
                    striped: true,
                    singleSelect: false,
                    loadMsg: "正在加载数据，请稍后...",
                    queryParams: {accountnum:accountnum,accountdate:accountdate},
                    columns:[[
                        {field: 'ck', checkbox: true},
                        {title: '账户名称', field: 'accountname', width: 110},
                        {title: '账户',	field: 'accountnum',width:120},
                        {title: '银行名称',	field: 'bankname',width:150},
                        {title: '日期', field: 'accountdate', width: 120},
                        {title: '金额', field: 'money',width:150}
                    ]],
                    toolbar: '#toolbar'
                });

                $(window).resize(function() {
                    $('#MainGrid').datagrid('resize');
                });
            }

            $('#accountnum').combogrid({
                panelWidth:550,
                idField:'accountcode',
                textField:'accountcode',
                url:prefix+'/base/basedata/findBank',
                columns:[[
                    {field: 'ck', checkbox: true},
                    {field:'cantonname',title:'区划',width:80},
                    {field:'accountcode',title:'账号',width:160},
                    {field:'bankname',title:'开户行名称',width:260}
                ]]
            });

            //收款银行下拉框
            $('#bankid').combogrid({
                panelMaxHeight: 180,
                panelWidth:600,
                idField:'bankid',
                textField:'bankname',
                url:prefix + '/base/basedata/findBank',
                columns:[[
                    {field:'accountcode',title:'收款人账号',width:80},
                    {field:'accountname',title:'收款人全称',width:160},
                    {field:'bankname',title:'收款人开户银行',width:260}
                ]],
            });
            $('#bankid').combo({
                onChange: function(){
                    var g = $('#bankid').combogrid('grid');	// get datagrid object
                    var r = g.datagrid('getSelected');
                    $('#accountcode').val(r.accountcode);
                    $('#accountname').val(r.accountname);
                }
            })
            function editInfo(opt) {
                if(opt==1){
                    $('#form-update').form('clear');
                }else{
                    var rows = $('#MainGrid').datagrid('getSelections');
                    if (rows.length ==0) {
                        $.messager.alert('提示', '请选择要编辑的数据', 'info');
                        return;
                    }
                    if (rows.length>1) {
                        $.messager.alert('提示', '修改操作不能多选', 'info');
                        return;
                    }
                    $('#form-update').form('load',rows[0]);
                }
                showForm(opt);
            }

            function showForm(opt) {
                var tit = (opt == 2) ? '修改网银缴费' : '新增网银缴费';
                $("#box-update").removeClass('hide').dialog({
                    title: '&nbsp;' + tit,
                    iconCls: 'icon-add',
                    width: 800,
                    height: 600,
                    modal: true,
                    buttons: [{
                        text: '保存',
                        iconCls: 'icon-ok',
                        width: 80,
                        plain: false,
                        handler: function () {
                            updateInfo();
                        }
                    }, {
                        text: '取消',
                        iconCls: 'icon-cancel',
                        width: 80,
                        plain: false,
                        handler: function () {
                            $('#box-update').dialog('close')
                        }
                    }]
                });
            }
            //待查新增修改
            function updateInfo() {
                var url = '/bill/bankcheckbill/editWebpay';
                $('#form-update').form({
                    url: prefix + url,
                    onSubmit:function(){
                        var isValid = $(this).form('validate');
                        if (isValid){
                            $.messager.progress({
                                title: '提示',
                                msg: '数据处理中，请稍候……',
                                text: ''
                            });
                        }
                        return isValid;
                    },
                    success:function(data) {
                        $.messager.progress('close');
                        var data = eval('(' + data + ')');
                        if (data.success) {
                            searchInfo();
                            $('#box-update').dialog('close');
                        }
                        $.messager.alert('提示', data.msg, 'info');
                    }
                });
                $('#form-update').submit();
            }

            //----------------------- 发送弹窗
            function deleteInfo() {
                var rows = $('#MainGrid').datagrid('getSelections');
                if (rows.length == 0) {
                    $.messager.alert('提示', '请选择要删除的数据', 'info');
                    return;
                }

                var list = [];
                $.each(rows, function (index, value) {
                    list.push(value.bankcheckid)
                });
                console.log(list.toString());
                $.messager.confirm('确认', '您确认想要删除记录吗？', function (r) {
                    if (r) {
                        $.ajax({
                            url: prefix + '/bill/bankcheckbill/deleteWebpay',
                            type: 'POST',
                            data: {bankcheckids: list.toString()},
                            dataType: 'json',
                            success: function (data) {
                                if (data.success) {
                                    $.messager.show({
                                        title: '删除',
                                        msg: '数据删除成功',
                                        showType: 'slide'
                                    })
                                    searchInfo();
                                } else {
                                    $.messager.alert('提示', data.msg, 'info');
                                }
                            }
                        });
                    } else {//没选中
                        return false;
                    }
                })
            }



            function cancelInfo() {
                $('#SendBox-add').dialog('close')
            }

            function exportInfo() {
                var downurl = prefix + '/bill/bankcheckbill/webpayExport?1=1';
                var accountnum = $('#accountnum').val();
                var accountdate = $('#accountdate1').val();
                // if(accountnum==null||accountnum==''){
                //     $.messager.alert('提示', '请选择收款账户', 'info');
                //     return;
                // }

                accountnum == "" ? downurl = downurl : downurl = downurl + "&accountnum=" + accountnum;
                accountdate == "" ? downurl = downurl : downurl = downurl + "&accountdate=" + accountdate;
                window.location.href = downurl;
            }

        </script>
	</body>
</html>
